<?php

class module {

	var $zam;

	function main()
	{
		switch ($this->zam->data['params'][1])
		{
			default:
				$this->index();
				break;
			case 'logout':
				$this->logout();
				break;
		}
	}
	
	#=============================
	# Index
	#=============================
	function index()
	{
		$result = $this->zam->sql->construct( array(
			'action'	=>	'select',
			'db'		=>	constant('DB_SESSIONS'),
			'order'		=>	'stime'
		) );
		
		$guests = 0;
		$usrs = 0;
		
		while ( $users = $this->zam->sql->fetch() )
		{
			if ( $users['member_id'] == 0 )
			{
				$guests++;
			}
			else
			{
				$online .= "<a href=\"{$this->zam->url}user/{$users['member_id']}\">{$users['suser']}</a>, ";
				$usrs++;
			}
		}
				
		$online = preg_replace('/, $/', '', $online);
		
		$this->zam->skin->set_vars( array(
			'title'		=>	'Home',
			'head'		=>	$this->zam->tags->stylesheet('main.css'),
			'subtemp'	=>	'index.tpl',
			'online'	=>	$online,
			'guests'	=>	$guests,
			'users'		=>	$usrs,
		) );
		
		$this->zam->skin->display('template.tpl');
	}
	
	#=============================
	# Set language
	# (Currently not in use)
	#=============================
	/*function setlang()
	{
		$this->zam->sess->setsession( array( 'slang' => $this->zam->data['get']['charset'] ) );
		
		$this->zam->skin->set_var('to', '');
		$this->zam->skin->display('redirect.tpl');
	}*/
	
	#=============================
	# Logout
	#=============================
	function logout()
	{
		if ( $this->zam->sess->is_logged_in() )
		{
			$this->zam->sess->setsession( array( 'member_id' => 0, 'suser' => 'Guest' ) );
			$this->zam->sess->setcookie('mid', '', -3600);
			$this->zam->sess->setcookie('passhash', '', -3600);
			$this->zam->sess->setcookie('loginkey', '', -3600);
			
			# Redirect
			header("Location: {$this->zam->url}");
		}
	}
}

?>